package com.songcan.common.context;


import java.util.List;
import java.util.Set;

/**
 * 线程中存储token以及userid，待补充
 */
public class UserContext {

    private static final ThreadLocal<String> userId = new ThreadLocal<>();
    private static final ThreadLocal<String> token = new ThreadLocal<>();
    private static final ThreadLocal<Set<String>> deptIds = new ThreadLocal<>();
    private static final ThreadLocal<List<String>> roles = new ThreadLocal<>();


    public static void  set(String userId1,Set<String> deptId1){
        userId.set(userId1);
        deptIds.set(deptId1);
    }

    public static void set(String userId1,Set<String> deptIds1,List<String> roles1) {
        userId.set(userId1);
        deptIds.set(deptIds1);
        roles.set(roles1);
    }



    public static String getUserId() {
        return userId.get();
    }
    public static String getToken() {
        return token.get();
    }
    public static Set<String> getDeptIds(){return deptIds.get();}
    public static List<String>  getRoles(){return  roles.get();}

    public static void remove(){
        userId.remove();
        token.remove();
        deptIds.remove();
        roles.remove();
    }

    public static void setToken(String accessToken){
        token.set(accessToken);
    }
    public static void setUserId(String userIds){
        userId.set(userIds);
    }
    public static void setDeptIds(Set<String> deptId){deptIds.set(deptId);}
    public static void setRoles(List<String> roles1){roles.set(roles1);}
}
